function stdshade(amatrix,alpha,acolor,F,smth)
% usage: stdshading(amatrix,alpha,acolor,F,smth)
% plot median and sem/std coming from a matrix of data, at which each row is an
% observation. sem/std is shown as shading.
% - acolor defines the used color (default is red) 
% - F assignes the used x axis (default is steps of 1).
% - alpha defines transparency of the shading (default is no shading and black median line)
% - smth defines the smoothing factor (default is no smooth)
% smusall 2010/4/23

if exist('acolor','var')==0 || isempty(acolor)
    acolor='r'; 
end

if exist('F','var')==0 || isempty(F); 
    F=1:size(amatrix,2);
end

if exist('smth','var'); if isempty(smth); smth=1; end
else smth=1;
end  

if ne(size(F,1),1)
    F=F';
end

[amean,quartm,quartp]= median_p(amatrix);

if exist('alpha','var')==0 || isempty(alpha) 
    fill([F fliplr(F)],[quartp fliplr(quartm)],acolor,'linestyle','none');
    acolor='k';
else fill([F fliplr(F)],[quartp fliplr(quartm)],acolor, 'FaceAlpha', alpha,'linestyle','none');    
end

if ishold==0
    check=true; else check=false;
end

hold on;plot(F,amean,acolor,'linewidth',2.5); %% change color or linewidth to adjust median line

if check
    hold off;
end

end



